﻿/// <reference path="../jquery-2.0.2.min.js" />/// <reference path="../MJ_JSComment.js" />

function getdata(indexpage, indexwhere) {
    poststr = "{\"type\":\"dormcombolist\",\"pagecurrent\":\"" + indexpage + "\",\"indexwhere\":\"" + indexwhere + "\"}";
    mj_js_ajax("json", poststr, showlist);

}
var xuhao = 1;
var color = 1;
function showlist(data) {
    if (data.result == "ok") {
    try{
        var record_count = data.record_count;
        var page_curent = data.page_curent;
        var datatable = data.table;

        var str = "";
        var table = document.getElementById("tbodyList");
        $("#tbodyList").empty();
        for (var i = 0; i < datatable.length; i++) {
            var tr = document.createElement("tr");
            if (color % 2 != 0) {
                tr.className = "bg-info";
                color++;
            }
            else {
                tr.className = "bgwhite";
                color++;
            }
           
            var td3 = document.createElement("td");
            td3.innerHTML = datatable[i].Louhao;
            var td4 = document.createElement("td");
            td4.innerHTML = datatable[i].sushe_number;



            var td5 = document.createElement("td");
            td5.setAttribute("contenteditable", "true");
            td5.id = datatable[i].id + "brand";
            td5.innerHTML = datatable[i].brand.toString().replace("C套餐", "").replace("A套餐", "").replace("B套餐", "").replace("D套餐", "");
          

            var td6 = document.createElement("td");
            td6.setAttribute("contenteditable", "true");
            td6.id = datatable[i].id + "tongshu";
            td6.innerHTML = datatable[i].tongshu.toString();

            var td7 = document.createElement("td");
            td7.setAttribute("contenteditable", "true");
            td7.id = datatable[i].id + "shengyu_tongshu";
            td7.innerHTML = datatable[i].shengyu_tongshu.toString();

            

            var td8 = document.createElement("td");
            td8.setAttribute("contenteditable", "true");
            td8.id = datatable[i].id + "qiantong";
            td8.innerHTML = datatable[i].qiantong.toString();


            var td9 = document.createElement("td");
            td9.setAttribute("contenteditable", "true");
            td9.id = datatable[i].id + "shuifei";
            td9.innerHTML = datatable[i].shuifei.toString();

           

            var td10 = document.createElement("td");
            td10.setAttribute("contenteditable", "true");
            td10.id = datatable[i].id + "yajin";
            td10.innerHTML = datatable[i].yajin.toString();

           

            var td11 = document.createElement("td");
            td11.setAttribute("contenteditable", "true");
            td11.id = datatable[i].id + "yishou";
            td11.innerHTML = datatable[i].yishou.toString();
           

            var td13 = document.createElement("td");
            var input0 = document.createElement("input");
            input0.setAttribute("type","text");
            input0.value = datatable[i].beizu.toString();
            input0.id = datatable[i].id + "beizu";
            input0.className = " btn-default INPUT0 INPUT2 INPUT3";
            td13.appendChild(input0);


            var td14 = document.createElement("td");
            if (datatable[i].time != null) {
                td14.innerHTML = datatable[i].time.replace(/-/g, "/").substring(0, 10);
            }
            else {td14.innerHTML = datatable[i].time; }

            var td15 = document.createElement("td");
            var select = document.createElement("select");
            select.id = datatable[i].id + "select";
            var option = document.createElement("option");
            option.setAttribute("value", "weishouqi");
            option.innerHTML = "未收齐";
            var option1 = document.createElement("option");
            option1.setAttribute("value", "yishouqi");
            option1.innerHTML = "已收齐";
           
            var statee = $.trim(datatable[i].state);
            if (statee == "0") {
                option1.setAttribute("selected", "selected");
            }
            else if (statee == "1") {
                option.setAttribute("selected", "selected");
            }
            select.appendChild(option);
            select.appendChild(option1);
            td15.appendChild(select);
           
            var td16 = document.createElement("td");
            var label1 = document.createElement("input");
            label1.id = datatable[i].id;
            label1.value = "修改";
            label1.setAttribute("type", "button");
            label1.className = "btn btn-info input1";
            label1.onclick = function () {
                xiugai(this.id);

            }
            var label2 = document.createElement("input");
            label2.id = datatable[i].id;
            label2.value = "删除";
            label2.setAttribute("type", "button");
            label2.className = "btn btn-default input2";
            label2.onclick = function () {
                delect(this.id);

            }
            td16.appendChild(label1);
            td16.appendChild(label2);
           
           // tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);
            tr.appendChild(td5);
            tr.appendChild(td6);
            tr.appendChild(td7);
            tr.appendChild(td8);
            tr.appendChild(td9);
            tr.appendChild(td10);
            tr.appendChild(td11);
            tr.appendChild(td13);
            tr.appendChild(td14);
            tr.appendChild(td15);
            tr.appendChild(td16);
            table.appendChild(tr);
        }

        //下面进行的是分页
        $("#record_shu").text(" 总记录数" + record_count);
        if (record_count % 10 != 0) {
            page_shu = record_count / 10 + 1;
            page_shu = parseInt(page_shu)
        }
      
      
        else {
            page_shu = record_count / 10;
        }

        
        var options = {
          //  currentPage: page_curent,
            totalPages: page_shu,
            numberOfPages: 5,
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "第一页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "最后一页";
                    case "page":
                        return page;
                }
            },
            onPageClicked: function (event, originalEvent, type, page) {
                if (page == 1) {
                    xuhao = 1;
                }
                else {
                    var n = page - 1;
                    xuhao = n * 10+1;
                }
                var quyu = $.trim($("#dateboxs").text());
                var louhao = $.trim($("#building").val());
                var sushe_hoa = $.trim($("#dorm").val());
                var zhuangtai = $.trim($("#Span1").text());
                var brand = $.trim($("#list").text());
                var arrey = quyu + "|" + louhao + "|" + sushe_hoa + "|" + zhuangtai + "|" + brand;
                getdata(page, arrey);
            }
        }
        $('#example').bootstrapPaginator(options);
    }
     
      catch(e){
        
        }
  }
    else {
        layer.alert(data.msg, {
            icon: 1,
            skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
        })

    }

}

function xiugai(id) {
    var brand = $.trim($("#" + id + "brand").text());
    var tongshu = $.trim($("#" + id + "tongshu").text());
    var shengyu_tongshu = $.trim($("#" + id + "shengyu_tongshu").text());
    var qiantong = $.trim($("#" + id + "qiantong").text());
    var shuifei = $.trim($("#" + id + "shuifei").text());
    var yajin = $.trim($("#" + id + "yajin").text());
    var yishou = $.trim($("#" + id + "yishou").text());
    var beizu = $.trim($("#" + id + "beizu").val());
    var state = $("#" + id + "select").find("option:selected").text();
    var str = id + "|" + brand + "|" + tongshu + "|" + shengyu_tongshu + "|" + qiantong + "|" + shuifei + "|" + yajin + "|" + yishou + "|" + state + "|" + beizu;
    poststr = "{\"type\":\"dormcombolist_xiugai\",\"dormcombolist_value\":\"" + str + "\"}";
    mj_js_ajax("json", poststr, xiugai_statue);
 }

 function xiugai_statue(data) {
     layer.alert(data.msg, {
         icon: 1,
         skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
     })

  }
  var delete_;
  function delect(id) {
      if ($.cookie("manager_name") != "yidashuihang") {
          alert("权限不够，不能删除数据！");
          return;
      }
     delete_ = id;
     $("#content_two").text("确定要删除这条记录？");
     $("#LoginBox_two").fadeIn("fast");
     $("#LoginBox_two").css({ display: 'block' });
 }



 function yes_button() {
    var    id = delete_
     var quyu = $.trim($("#dateboxs").text());
     var louhao = $.trim($("#building").val());
     var sushe_hoa = $.trim($("#dorm").val());
     var zhuangtai = $.trim($("#Span1").text());
     var brand = $.trim($("#list").text());
     var arrey = quyu + "|" + louhao + "|" + sushe_hoa + "|" + zhuangtai + "|" + brand;

     poststr = "{\"type\":\"dormcombolist_delect\",\"dormcombolist_id\":\"" + id + "\",\"pagecurrent\":\"1\",\"indexwhere\":\"" + arrey + "\"}";
     mj_js_ajax("json", poststr, showlist);
     $("#LoginBox_two").fadeOut("fast");
     $("#LoginBox_two").css({ display: 'none' });
 }
 function no_button() {
     $("#LoginBox_two").fadeOut("fast");
     $("#LoginBox_two").css({ display: 'none' });

 }

